import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '首页',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

 
  {
    path: '/project',
    component: Layout,
    redirect: '/project/project',
    name: '项目管理',
    meta: {
      title: '项目管理',
      icon: 'nested'
    },
    children: [
      {
        path: '/project/project',
        component: () => import('@/views/project/project'),
        name: '项目列表',
        meta: { title: '项目列表' },
      },
      {
        path: '/project/projectFolder',
        component: () => import('@/views/project/projectfiles/projectFolder'),
        hidden:true,
        name: '项目资料文件夹',
        meta: { title: '项目资料文件夹' }
      },
      {
        path: '/project/projectfiles',
        component: () => import('@/views/project/projectfiles/projectFiles'),
        hidden:true,
        name: '项目资料文件列表',
        meta: { title: '项目资料文件列表' }
      },
      {
        path: '/project/projectAdd',
        component: () => import('@/views/project/projectAdd'),
        hidden:true,
        name: '项目图文信息',
        meta: { title: '编辑项目图文信息' }
      },
      {
        path: '/project/projectEdit',
        component: () => import('@/views/project/projectEdit'),
        hidden:true,
        name: '编辑项目信息',
        meta: { title: '编辑项目信息' }
      },
      {
        path: '/project/projectInfo',
        component: () => import('@/views/project/projectInfo'),
        hidden:true,
        name: '添加项目信息',
        meta: { title: '新增项目信息' }
      },
      {
        path: 'examine',
        component: () => import('@/views/project/examine'),
        name: '项目审核',
        meta: { title: '项目审核' }
      },{
        path: '/contract',
        component: () => import('@/views/project/contract'),
        name: '合同审核',
        meta: { title: '合同审核' },
      },
      {
        path: '/contract/contractFile',
        component: () => import('@/views/project/contractFile'),
        hidden:true,
        name: '合同文件',
        meta: { title: '合同文件' },
      },
    ]
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/user',
    name: 'user',
    meta: { title: '用户管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/user/user',
        name: 'user',
        component: () => import('@/views/users/user'),
        meta: { title: '普通用户列表', icon: 'table' }
      },
      {
        path: '/user/userEdit',
        component: () => import('@/views/users/userEdit'),
        hidden:true,
        name: '编辑用户信息',
        meta: { title: '编辑用户信息' }
      },
      {
        path: '/user/storeUser',
        name: 'user',
        component: () => import('@/views/users/storeList'),
        meta: { title: '商家用户列表', icon: 'table' }
      }
    ]
  },
  // {
  //   path: '/user',
  //   component: Layout,
  //   redirect: '/users/user',
  //   name: 'user',
  //   meta: { title: '财务管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'user',
  //       name: 'user',
  //       component: () => import('@/views/users/user'),
  //       meta: { title: '提现管理', icon: 'table' }
  //     },
  //     {
  //       path: 'tree',
  //       name: 'Tree',
  //       component: () => import('@/views/tree/index'),
  //       meta: { title: '项目', icon: 'tree' }
  //     }
  //   ]
  // },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/banner',
    name: 'system',
    meta: { title: '系统设置', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'banner',
        name: 'banner',
        component: () => import('@/views/system/banner'),
        meta: { title: 'banner管理', icon: 'table' }
      },
      {
        path: 'applet',
        name: 'applet',
        component: () => import('@/views/system/applet'),
        meta: { title: '小程序设置', icon: 'tree' }
      }
    ]
  },

  {
    path: '/finance',
    component: Layout,
    redirect: '/finance/banner',
    name: 'finance',
    meta: { title: '财务管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'authentication',
        name: 'authentication',
        component: () => import('@/views/finance/authentication'),
        meta: { title: '费用设置', icon: 'table' }
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/finance/userOrder'),
        meta: { title: '订单管理', icon: 'tree' }
      },
      {
        path: 'applet',
        name: 'applet',
        component: () => import('@/views/system/applet'),
        meta: { title: '提现申请', icon: 'tree' }
      }
    ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
